/*
Package v1
@Time : 2022/12/21 21:20
@Author : 董胜烨
@File : salary
@Software: GoLand
@note:
*/
package v1

import (
	"employee/service"
	"fmt"
	"github.com/gin-gonic/gin"
	"strconv"
)

func InsertSalary(c *gin.Context) {
	salary := &service.Salary{}
	err := c.BindJSON(salary)
	if err != nil {
		fmt.Println("InsertSalary error:", err)
	}
	ok := salary.Insert()
	if ok {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "插入成功",
		})
	} else {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "插入失败",
		})
	}
}
func UpdateSalary(c *gin.Context) {
	salary := &service.Salary{}
	err := c.BindJSON(salary)
	if err != nil {
		fmt.Println("UpdateSalary error:", err)
	}
	ok := salary.Update()
	if ok {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "修改成功",
		})
	} else {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "修改失败",
		})
	}
}
func DeleteSalary(c *gin.Context) {
	salary := &service.Salary{}
	err := c.BindJSON(salary)
	if err != nil {
		fmt.Println("DeleteSalary error:", err)
	}
	ok := salary.Delete()
	if ok {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "删除成功",
		})
	} else {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "删除失败",
		})
	}
}
func QuerySalary(c *gin.Context) {
	salary := &service.Salary{}
	var err error
	salary.EmployeeID, err = strconv.ParseInt(c.DefaultQuery("employee_id", "0"), 10, 64)
	if err != nil {
		fmt.Println("QuerySalary error:", err)
	}
	res := salary.Query()
	if res != nil {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "获取成功",
			"data": res,
		})
	} else {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "获取失败",
		})
	}
}
